🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / service / src / androidMain / kotlin / org / meshtastic / core / service / BootCompleteReceiver.kt
Displaying Raw • Download
core/service/src/androidMain/kotlin/org/meshtastic/core/service/BootCompleteReceiver.kt fix/qr-error-correction (7b45f84f) Text, 4.55 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.service
Tff7b72import T7ee787android.content.BroadcastReceiver
Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787android.content.Intent
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CancellationException
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.CoroutineStart
Tff7b72import T7ee787kotlinx.coroutines.SupervisorJob
Tff7b72import T7ee787kotlinx.coroutines.TimeoutCancellationException
Tff7b72import T7ee787kotlinx.coroutines.async
Tff7b72import T7ee787kotlinx.coroutines.cancel
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787kotlinx.coroutines.withTimeout
Tff7b72import T7ee787org.koin.core.component.KoinComponent
Tff7b72import T7ee787org.koin.core.component.inject
Tff7b72import T7ee787org.meshtastic.core.common.util.isValidDeviceAddress
Tff7b72import T7ee787org.meshtastic.core.di.CoroutineDispatchers
Tff7b72import T7ee787org.meshtastic.core.repository.MeshPrefs
T8b949e/** This receiver starts the MeshService on boot if a device was previously connected. */
Tff7b72class T56d364BootCompleteReceiver Tb4b4b4:
Te6edf3BroadcastReceiverTb4b4b4(Tb4b4b4)Tb4b4b4,
Te6edf3KoinComponent Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3meshPrefsTb4b4b4: Te6edf3MeshPrefs Tff7b72by Te6edf3injectTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3dispatchersTb4b4b4: Te6edf3CoroutineDispatchers Tff7b72by Te6edf3injectTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3scope Tff7b72by Te6edf3lazy Tb4b4b4{ Te6edf3CoroutineScopeTb4b4b4(Te6edf3SupervisorJobTb4b4b4(Tb4b4b4) Tff7b72+ Te6edf3dispatchersTb4b4b4.Te6edf3defaultTb4b4b4) Tb4b4b4}
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72override Tff7b72fun Td2a8ffonReceiveTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4, Te6edf3intentTb4b4b4: Te6edf3IntentTb4b4b4) Tb4b4b4{
T8b949e// Only these two actions carry a background foreground-service-start exemption. The manifest also filters the
T8b949e// OEM quick-boot actions, which do not, so acting on those would guarantee a rejected start.
Tff7b72if Tb4b4b4(Te6edf3intentTb4b4b4.Te6edf3action Tff7b72!in Te6edf3EXEMPT_ACTIONSTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3d Tb4b4b4{ Ta5d6ff"Ta5d6ffBootCompleteReceiver: ignoring non-exempt action Tffd700${Te6edf3intentTb4b4b4.Te6edf3actionTffd700}Ta5d6ff" Tb4b4b4}
Tff7b72return
Tb4b4b4}
Tff7b72val Te6edf3pendingResult Tff7b72= Te6edf3goAsyncTb4b4b4(Tb4b4b4)
Te6edf3scopeTb4b4b4.Te6edf3launchTb4b4b4(Te6edf3start Tff7b72= Te6edf3CoroutineStartTb4b4b4.Te6edf3UNDISPATCHEDTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Tff7b72val Te6edf3address Tff7b72=
Tff7b72try Tb4b4b4{
Te6edf3withTimeoutTb4b4b4(Te6edf3PREFERENCES_LOAD_TIMEOUT_MILLISTb4b4b4) Tb4b4b4{
T8b949e// Keep the IO read as a sibling so a queued dispatcher cannot delay timeout completion.
Tff7b72val Te6edf3preferencesLoad Tff7b72= Te6edf3scopeTb4b4b4.Te6edf3asyncTb4b4b4(Te6edf3dispatchersTb4b4b4.Te6edf3ioTb4b4b4) Tb4b4b4{ Te6edf3meshPrefsTb4b4b4.Te6edf3awaitDeviceAddressTb4b4b4(Tb4b4b4) Tb4b4b4}
Tff7b72try Tb4b4b4{
Te6edf3preferencesLoadTb4b4b4.Te6edf3awaitTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72finally Tb4b4b4{
Te6edf3preferencesLoadTb4b4b4.Te6edf3cancelTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3_Tb4b4b4: Te6edf3TimeoutCancellationExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffBootCompleteReceiver: timed out loading the selected deviceTa5d6ff" Tb4b4b4}
Tff7b72returnTf0883e@launch
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3CancellationExceptionTb4b4b4) Tb4b4b4{
Tff7b72throw Te6edf3e
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffBootCompleteReceiver: failed to load the selected deviceTa5d6ff" Tb4b4b4}
Tff7b72returnTf0883e@launch
Tb4b4b4}
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3isValidDeviceAddressTb4b4b4(Te6edf3addressTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3d Tb4b4b4{ Ta5d6ff"Ta5d6ffBootCompleteReceiver: no device previously connected, skipping service startTa5d6ff" Tb4b4b4}
Tff7b72returnTf0883e@launch
Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffBootCompleteReceiver: starting MeshService after Tffd700${Te6edf3intentTb4b4b4.Te6edf3actionTffd700}Ta5d6ff" Tb4b4b4}
Te6edf3MeshServiceTb4b4b4.Te6edf3startServiceTb4b4b4(Te6edf3contextTb4b4b4, Te6edf3ServiceStartTriggerTb4b4b4.Te6edf3BootCompletedTb4b4b4)
Tb4b4b4} Tff7b72finally Tb4b4b4{
Te6edf3pendingResultTb4b4b4.Te6edf3finishTb4b4b4(Tb4b4b4)
Te6edf3scopeTb4b4b4.Te6edf3cancelTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tff7b72private Tff7b72companion Tff7b72object Tb4b4b4{
Tff7b72const Tff7b72val Te6edf3PREFERENCES_LOAD_TIMEOUT_MILLIS Tff7b72= T79c0ff5Te6edf3_000L
T8b949e/**
* `MY_PACKAGE_REPLACED` is filtered by the manifest so an in-place upgrade restores the radio link without
* waiting for the user to reopen the app, and it is exempt from the background-start restriction just as
* `BOOT_COMPLETED` is.
*/
Tff7b72val Te6edf3EXEMPT_ACTIONS Tff7b72= Te6edf3setOfTb4b4b4(Te6edf3IntentTb4b4b4.Te6edf3ACTION_BOOT_COMPLETEDTb4b4b4, Te6edf3IntentTb4b4b4.Te6edf3ACTION_MY_PACKAGE_REPLACEDTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s